using BasicScript.Component;
using Game.Core;
using Game.Main.Model;
using Game.Manager;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class TVItem : BaseItem
	{
		private Transform display;

		private int index;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			display = model.Find("Light");
			SetDisplay(data.state);
		}

		public override void QuicklyTouch(TouchEventData touchEventData)
		{
			base.QuicklyTouch(touchEventData);
			SetDisplay(index + 1);
			Singleton<AudioManager>.Instance.PlaySound("sound_tv_change");
		}

		private void SetDisplay(int val)
		{
			if (index != val)
			{
				index = val;
				SpriteAssets component = display.GetComponent<SpriteAssets>();
				if (index < 0)
				{
					index = component.data.sprites.Count - 1;
				}
				else if (index >= component.data.sprites.Count)
				{
					index = 0;
				}
				SpriteRenderer component2 = display.GetComponent<SpriteRenderer>();
				component2.sprite = component.data.sprites[index];
			}
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = index;
		}
	}
}
